<%@page import="dal.project.Project"%>
<%@page import="dal.project.ProjectUtil"%>
<%@page import="dal.employee.Employee"%>
<%@page import="dal.employee.EmployeeUtil"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Project Team Add</title>
</head>
<script type="text/javascript"
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script type="text/javascript"
	src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>


<script type="text/javascript">
	
	$(document).ready(
			function() {

				$("#projectTeamAdd").submit(function(e){
					e.preventDefault();
				}); 

				$("#btnAdd").click(
						function(e) {
							dataString = $("#projectTeamAdd").serialize();

							var prjTeam = $("input#TeamName").val();
							var prjId = $("#project_id").val();
							var prjName = $("input#ProjectName").val();
							dataString = "TeamName=" + prjTeam + "&project_id="
									+ prjId + "&ProjectName=" + prjName;
							//alert(dataString);
							$.ajax({
								type : "POST",
								url : "AddProjectTeam",
								data : dataString,
								dataType : "json",

								success : function(data, textStatus, jqXHR) {

									if (data.success) {
										
 										alert("Team Generated Successfully");
										$("input:text#TeamName").val("");
										$("input:text#project_id").val("");
										$("input:text#ProjectName").val("");
										
										
										
										$("#projectTeamAdd").css("display", "none");
										$("#teamMemberAdd").css("display", "block");
										
										$("input:text#TeamId").val(data.teamId);
										
										
									} else {
										/* $("#statusText").html("");
										$("#statusText")
												.append(data.statusText);
										 */		
										alert("Unable To Generate Team");		
									}
								},
								error : function() {
										alert("Error While processing Request");
								}
							});
						});
						
						
						$("#AddTeam").click(
						function(e) {
							//alert("kk");
							dataString = $("#AddProjectTeamMember").serialize();

							var prjTeamId = $("input#TeamId").val();
							var prjEmployeeId = $("#EmployeeId").val();
							var prjRole = $("input#Role").val();
							dataString = "TeamId="+prjTeamId+"&EmployeeId="+prjEmployeeId+"&Role="+prjRole;
							$.ajax({
								type : "POST",
								url : "AddProjectTeamMember",
								data : dataString,
								dataType : "json",

								success : function(data, textStatus, jqXHR) {

									
										
 										alert("Employee Added Successfully");
										$("#EmployeeId").val("");
										$("input:text#Role").val("");
										$("input:text#TeamId").val(data.TeamId);
											//alert(TeamId);							
										
										$("#projectTeamAdd").css("display", "none");
										$("#teamMemberAdd").css("display", "block");
										
										
										
										
									
								},
								error : function() {
										alert("Error While processing Request");
								}
							});
						});
						
						
				$("#project_id").change(
						function(e) {
							dataString = $("#projectTeamAdd").serialize();
							var prjId = $("#project_id").val();
							
							dataString = "project_id="+prjId;
							$.ajax({
								type : "POST",
								url : "GetProjectNameByID",
								data : dataString,
								dataType : "json",

								success : function(data, textStatus, jqXHR) {
										
									$("input:text#ProjectName").val(data.projectName);	
										
								},
								error : function() {
									alert("Error occured while processing");
								}
							});  
						});		
						
			});
</script>

<body>

	<h1>Project Team Add</h1>

	<%
		
		ArrayList<Object> al = new ProjectUtil().get();
		 %>


	<form id="projectTeamAdd">
		<table>
			<tr>
				<td>Team Name</td>
				<td><input type="text" name="TeamName" id="TeamName" required /></td>
			</tr>

			<tr>
				<td>Project Id</td>
				<td><select name="project_id" id="project_id">

						<option value=" ">Select Project ID</option>

						<%
								try {
	
									if (al.size() > 0) {
										for (Object ob : al) {
											Project project = (Project) ob;
											String project_id = project.getProjectId();
							%>
						<option value="<%=project_id%>"><%=project_id%></option>

						<%
										}
									}
							%>
				</select> <%
							 	} catch (Exception e) {
							 		e.printStackTrace();
							 	}
 					%></td>
			</tr>
			<tr>
				<td>Project Name</td>
				<td><input type="text" name="ProjectName" id="ProjectName"
					value=" " readonly="readonly"></td>
			</tr>
			<tr>
				<td></td>
				<td><input type="submit" value="Add" id="btnAdd"></td>
			</tr>
		</table>
	</form>






	<div id="teamMemberAdd" style="display: none; background-color: red;">
		<form id="AddProjectTeamMember">
			<table>
				<%
		
		ArrayList<Object> al1=new EmployeeUtil().get();
		 %>
				<tr>
					<td>Team Id</td>
					<td><input type="text" name="TeamId" id="TeamId"
						readonly="readonly"><br></td>
				</tr>
				<tr>
					<td>Employee Id</td>
					<td>
						<select name="EmployeeId" id="EmployeeId">

							<option value=" ">Select Employee ID</option>

							<%
								try {
										if (al1.size() > 0) {
											for (Object ob : al1) {
												Employee employee=(Employee)ob;
										
								%>
												<option value="<%=employee.getEmployeeId() %>"><%=employee.getName()%></option>
	
								<%
											}
										}
						%>
						</select> 
						<%
							 	} catch (Exception e) {
							 		e.printStackTrace();
							 	}
 					%>
 					</td>
				</tr>
				<tr>
					<td>Role</td>
					<td><input type="text" name="Role" id="Role"><br></td>
				</tr>

				<tr>
					<td></td>
					<td><input type="button" value="AddTeam" id="AddTeam"
						name="AddTeam"></td>
				</tr>
			</table>
		</form>
	</div>


</body>
</html>